﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MMITDomain.Abstract;
using MMITDomain.Entities;

namespace MMITDomain.Concrete
{
    public class EFVoucherRepository : IVoucherRepository
    {
        private EFDbContext dbContext = new EFDbContext();

        #region IVoucherRepository Members

        public IQueryable<Voucher> Vouchers
        {
            get 
            {
                return dbContext.Vouchers;
            }
        }

        public void SaveVoucher(Voucher objVoucher)
        {
            if (objVoucher.Id == 0)
            {
                dbContext.Vouchers.Add(objVoucher);
            }
          

            dbContext.SaveChanges();
        }


        public void DeleteVoucher(Voucher objVoucher)
        {
            dbContext.Vouchers.Remove(objVoucher);

            dbContext.SaveChanges();
        }

        public Voucher GetVoucherById(int iVoucherId)
        {
            return dbContext.Vouchers.Find(iVoucherId);
        }
        #endregion
    }
}
